package com.hugesoft.jxgs;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.hugesoft.commonlogic.dao.DaoManager;
import com.hugesoft.jxgs.activity.QuitDialogActivity;
import com.hugesoft.utils.FileUtil;

public class JXGSApplication extends Application {
	public static String APPPATH;
	private SDCardListener mSdReceiver;
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
//		CrashHandler crashHandler = CrashHandler.getInstance();
//		crashHandler.init(getApplicationContext());
//        NetworkEngine.getEngine();
//        NetworkService.actionStart(this);
		DaoManager.initDaoManager(this);
//        PushManager.shareManager().setContext(getApplicationContext());
//        LogicManager.friendManager().setmContext(getApplicationContext());
//        HeartBeatManager.shareManager();
        APPPATH = getApplicationContext().getFilesDir().getAbsolutePath();
        FileUtil.ensureDir(FileUtil.getFullAppDataPath());
        IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
		filter.addDataScheme("file");
		mSdReceiver = new SDCardListener();
		registerReceiver(mSdReceiver, filter);
	}
	class SDCardListener extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			if (intent.getAction().equals("android.intent.action.MEDIA_UNMOUNTED")) {
				jump();
			}

		}
	}
	public void backToDesk(){
		Intent intent= new Intent(Intent.ACTION_MAIN);
		 intent.addCategory(Intent.CATEGORY_HOME);
		 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		 startActivity(intent);
		 System.exit(0);
	}
	public void jump(){
		Intent i = new Intent(getApplicationContext(), QuitDialogActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(i);
	}
	
}
